using Cmpp.Client.Cmpp3Message.Utility;

namespace Cmpp.Client.Cmpp3Message {
    public class Cmpp3Header {
        private const int DEFAULT_HREADER_LENGTH = 12;
        private readonly Cmpp3Command m_command;
        private readonly uint m_sequenceId;
        private readonly uint m_totalLength;

        public Cmpp3Header(Cmpp3Command command) {
            m_command = command;
            m_sequenceId = DataConvert.CreateSequenceId();
            m_totalLength = DEFAULT_HREADER_LENGTH;
        }

        internal Cmpp3Header(CmppMessageReader reader) {
            m_totalLength = reader.ReadUInt32();
            m_command = (Cmpp3Command) reader.ReadUInt32();
            m_sequenceId = reader.ReadUInt32();
        }

        public Cmpp3Command Command {
            get {
                return m_command;
            }
        }

        public uint SequenceId {
            get {
                return m_sequenceId;
            }
        }

        public uint TotalLength {
            get {
                return m_totalLength;
            }
        }

        public void Write(CmppMessageWriter writer) {
            writer.Write(m_totalLength);
            writer.Write((uint) m_command);
            writer.Write(m_sequenceId);
        }
    }
}